<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.util.*, java.text.*;" errorPage=""%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%! DateFormat tipe = new SimpleDateFormat("EEE, MMM d, yyyy");
    Calendar cal = Calendar.getInstance();%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="javaScript" src="includes/ajax.js"></script>
<script language="JavaScript" src="includes/date-picker.js"></script>
<script>
function carregarJanela(url){
	if (document.all) {
		if (!document.documentElement.scrollTop){
			scrollY = document.body.scrollTop;
		}else{
			scrollY = document.documentElement.scrollTop;
		}
	}else{
		scrollY = window.pageYOffset;
	}

	window.open(url,'pedido', 'width=820, height=550, top=60, left=200, scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

	window.setTimeout("window.scrollTo(1, scrollY);", 1);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Pedidos Absorvidos</title>
<link href="includes/estilo.css" rel="stylesheet" type="text/css">
<style type="text/css">
</style>
</head>
<body onLoad="form_filtro.txtCliente.focus();">
	<table border="0" align="center" cellpadding="0" cellspacing="0" width="780px">
	<tr>
	<td height="100px">
		<table border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
		<tr>
			<td align="center" width="110px"> <font color="#191970" size="1"><%=(tipe.format(cal.getTime()))%></font></td>
			<td width="30px"></td>
			<td><center><font color="blue" size="4"><b>Lista de pedidos absorvidos</b></font></center></td>
			<td align="right" width="100px"><img src="imagens/logoDican.jpg" width="100px"></td>
		</tr>
		</table>
	</td>
	</tr>
	<tr>
		<td><form name="form_filtro" method="post" action="ConsultaPedidos">
				  <table border="0" align="center" cellpadding="2" cellspacing="1">
	              <tr>
					<td align="left">
						<font size="1">C&oacute;digo/CNPJ/Nome Cliente: </font><input value="<%=request.getParameter("cliente")%>" name="cliente" type="text" class="combo1" id="txtBusca" onKeyPress="if(event.keyCode == 13) filtrar();" size="35" maxlength="20">
					</td>
	                <td align="right" nowrap><font size="1">De:</font></td>
	                <td>
						<input value="<%=request.getParameter("dateFrom")%>" class="combo1" type="text" name="dateFrom" size="10" maxlength="10" onFocus="javascript:vDateType='3'" onKeyUp="DateFormat(this,this.value,event,false,'3')" onBlur="DateFormat(this,this.value,event,true,'3')"><a href="javascript:show_calendar('form_filtro.dateFrom');" onmouseover="window.status='Date Picker';return true;" onmouseout="window.status='';return true;"><img src="imagens/show-calendar.gif" width=18 height=16 border=0 ></a>
					</td>
	                <td align="right" nowrap><font size="1">Ate:</font></td>
	                <td>
						<input value="<%=request.getParameter("dateTo")%>" class="combo1" type="text" name="dateTo" size="10" maxlength="10" onFocus="javascript:vDateType='3'" onKeyUp="DateFormat(this,this.value,event,false,'3')" onBlur="DateFormat(this,this.value,event,true,'3')"><a href="javascript:show_calendar('form_filtro.dateTo');" onmouseover="window.status='Date Picker';return true;" onmouseout="window.status='';return true;"><img src="imagens/show-calendar.gif" width=18 height=16 border=0 ></a>
					</td>
					<td>
						<input name="Button" type="submit" class="botaoazul" style="width:80px" value="Pesquisar">
					</td>
	              </tr>
	          </table>
			  </form>
	</tr>
	<tr>
		<td><hr color=navy size=3></td>
	</tr>
	<tr>
		<td><font size="1">Os pedidos est&atilde;o sujeitos a altera&ccedil;&atilde;o</font></td>
	</tr>
	<tr>
	<td>
		<table align="center" cellpadding="0" cellspacing="0" width="100%" style="border-bottom: solid 2px black;margin-bottom: 20px">
		<tr class="other" height="25px">
			<td align="center" width="72px" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>PEDIDO</b></font></td>
			<td align="center" width="75px" align="left" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>EMISS&Atilde;O</b></font></td>
			<td align="center" width="50px" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>ORIGEM</b></font></td>
			<td align="center" width="135px" align="left" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>CNPJ</b></font></td>
			<td align="left" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>CLIENTE</b></font></td>
			<td align="center" width="130px" align="left" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>NF / STATUS</b></font></td>
			<td align="center" width="30px" align="left" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>Saldo</b></font></td>
		</tr>
		<c:forEach var="listaPed" items="${pedidos}" varStatus="count">
			<tr class="${count.index % 2 == 0 ? 'even' : 'odd'}" height="30px">
				<td align="center" style="border-top: solid 1px black; border-left: solid 2px black;"><font size="1"><a href="#" onclick="javascript:carregarJanela('itensPedidosAbsorvidos.jsp?numPedido=${listaPed.numPedido}&clienteId=${listaPed.clienteId}&clienteNome=${listaPed.clienteNome}&clienteValue=${listaPed.clienteValue}&emissao=${listaPed.emissao}&docstatus=${listaPed.docstatus}&transpNome=${listaPed.transpNome}&cifoufob=${listaPed.cifoufob}&orderId=${listaPed.orderId}&org=${listaPed.org}')">${listaPed.numPedido}</a></font></td>
				<td align="center" style="border-top: solid 1px black;"><font size="1">&nbsp;<c:out value="${fn:substring(listaPed.emissao,0,10)}" /></font></td>
				<td align="center" style="border-top: solid 1px black; "><font size="1"><c:out value="${fn:substring(listaPed.org,6,20)}" /></font></td>
				<td align="center" style="border-top: solid 1px black;"><font size="1">${listaPed.clienteValue}</font></td>
				<td style="border-top: solid 1px black;"><font size="1">${listaPed.clienteNome}</font></td>
				<sql:query dataSource="jdbc/postgres" var="faturasPedido">
					SELECT DISTINCT coalesce(I.em_brcore_fiscalno,'LOTE') as fatura,I.c_invoice_id fatId,I.dateinvoiced::date as emissao,(SELECT COUNT(*) SOMA FROM C_ORDERLINE OL WHERE OL.qtyordered > OL.qtyinvoiced AND OL.c_order_id=I.c_order_id) as saldo
					FROM C_INVOICE I 
					WHERE I.c_order_id = ?;
					<sql:param>${listaPed.orderId}</sql:param>
				</sql:query>
					<td align="center" style="border-top: solid 1px black;"><font size="1">${listaPed.docstatus}
						<c:if test="${not empty faturasPedido.rows}">
							<c:forEach var="faturaPedido" items="${faturasPedido.rows}" varStatus="count">
							<br/><a href='#' onclick="javascript:carregarJanela('itensNotasPedidosAbsorvidos.jsp?faturaId=${faturaPedido.fatId}&fiscalNo=${faturaPedido.fatura}&origem=${fn:substring(listaPed.org,6,20)}emissao=${fn:substring(faturaPedido.emissao,0,10)}');">${faturaPedido.fatura}</a> - ${faturaPedido.emissao}
							</c:forEach>
						</c:if>
					</font>	
					</td>
				<!--<td align="center" style="border-top: solid 1px black;border-right: solid 2px black;">&nbsp; if segundo > 0 and saldo > 0 then response.write "<a href='#' onclick=""javascript:carregarJanela('itensSaldoPedidosAbsorvidos.asp?nro="&objRS("orderid")&"');""><img border='0' src='img/lupa.png'/></a>" %></td> -->
				<td align="center" style="border-top: solid 1px black;border-right: solid 2px black;"><font size="1">&nbsp;SALDO</font></td>
			</tr>
		</c:forEach>
		</table>
	</td>
	</tr>
	</table>
	<center>
	<input name="Button" type="submit" class="botaoazul" style="width:80px" value="Voltar" onclick="window.location.replace('reservada.jsp');">
	</center>
</body>
</html>